﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MOBAServer.Room
{
    public class MatchRoom : RoomBase<MobaClient>
    {
        /// <summary>
        /// 队伍1玩家ID
        /// </summary>
        public List<int> team1IdList;
        /// <summary>
        /// 队伍2玩家ID
        /// </summary>
        public List<int> team2IdList;


        public MatchRoom(int id, int count) : base(id, count)
        {
            int teamCount = count / 2;
            team1IdList = new List<int>(teamCount);
            team2IdList = new List<int>(teamCount);

        }
        /// <summary>
        /// 进入房间
        /// </summary>
        /// <param name="client"></param>
        /// <param name="playerId"></param>
        public bool Enter(MobaClient client,int playerId)
        {
            //容量大于数量
            if(team1IdList.Capacity>team1IdList.Count)
            {
                team1IdList.Add(playerId);
                base.EnterRoom(client);
                return true;
            }
            else if(team2IdList.Capacity>team2IdList.Count)
            {
                team2IdList.Add(playerId);
                base.EnterRoom(client);
                return true;
            }
            //房间已满
            return false;
        }
        /// <summary>
        /// 如果满了 就开始选人
        /// </summary>
        public bool IsFull {
            get {
                return team1IdList.Capacity == team1IdList.Count && team2IdList.Capacity == team2IdList.Count;
            } 
        }
        /// <summary>
        /// 离开房间
        /// </summary>
        /// <param name="client"></param>
        /// <param name="playerId"></param>
        /// <returns></returns>
        public bool LeaveRoom(MobaClient client,int playerId)
        {
            if (team1IdList.Contains(playerId))
            {
                team1IdList.Remove(playerId);
                base.LeaveRoom(client);
                return true;
            }
            else if (team2IdList.Contains(playerId))
            {
                team2IdList.Remove(playerId);
                base.LeaveRoom(client);
                return true;
            }
            return false;
        }
        /// <summary>
        /// 房间是否为空  空了就移除房间
        /// </summary>
        public bool IsEmpty
        {
            get {
                return team1IdList.Count == 0 && team2IdList.Count == 0;
            }
        }
    }
}
